package com.xmu.makerspace.controller;

import com.xmu.makerspace.model.SelectRoomVO;
import com.xmu.makerspace.model.SimpleTeamInfoVO;
import com.xmu.makerspace.model.TeamAccountDTO;
import com.xmu.makerspace.model.attendance.AttendanceNumberDTO;
import com.xmu.makerspace.model.attendance.AttendanceNumberVO;
import com.xmu.makerspace.service.TeamInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by status200 on 2017/9/1.
 *
 *
 */
@RestController
@RequestMapping("/api/team-in")
public class TeamInApiController {

    private final TeamInService teamInService;

    @Autowired
    public TeamInApiController(TeamInService teamInService) {
        this.teamInService = teamInService;
    }

    @PostMapping("confirm-enter")
    public void confirmEnter(@RequestBody Map<String,Object> data) throws IOException {
        teamInService.confirmEnter((String) data.get("teamId"));
    }

    @GetMapping("get-room-statistic")
    public List<SelectRoomVO> getRoomStatistic() {
        return teamInService.getRoomStatistic();
    }

    @GetMapping("all-team-attendance-info")
    public List<AttendanceNumberVO> allTeamAttendanceInfo() {
        return teamInService.getAllTeamAttendanceInfo();
    }

    @PostMapping("attendance-number-submit")
    public List<AttendanceNumberDTO> attendanceNumberSubmit(@RequestBody List<AttendanceNumberDTO> dtos) {
        return teamInService.attendanceNumberSubmit(dtos);
    }

    @GetMapping("all-team-need-to-sign-file")
    public List<SimpleTeamInfoVO> getAllTeamNeedToSignFile() {
        return teamInService.getAllTeamNeedToSignFile();
    }

    @PostMapping("sign-file-done")
    public void signFileDone(@RequestBody Map<String,Object> params) throws MessagingException {
        Integer teamId = (Integer) params.get("teamId");

        teamInService.signFileDone(teamId);
    }

    @PostMapping("set-team-account")
    public void setTeamAccount(@RequestBody TeamAccountDTO dto) {
        teamInService.setTeamAccount(dto);
    }
}
